package com.example.crud.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.crud.mapper.StudentMapper;
import com.example.crud.model.Student;
import com.example.crud.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * ClassName: StudentController
 * Package: com.example.crud.controller
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-01-15
 * Time: 17:06
 */

@RestController
@RequestMapping("/stu")
public class StudentController {

    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private StudentService studentService;

    //分页也查询
    @RequestMapping("/page")
    public Page<Student> page(){
        Page<Student> page = new Page<>(1,3);
        return studentMapper.selectPage(page,null);
    }


    //  service 添加
    @RequestMapping("/save")
    public void save(){
        Student student = new Student();
        student.setName("小明");
        student.setEmail("qwe@com.com");
        student.setClazzName("大一新生");
        boolean ret = studentService.save(student);
        System.out.println(ret);
    }

    @RequestMapping("/insert")
    public void insert(){
        Student student = new Student();
        student.setName("小红");
        int ret = studentMapper.insert(student);
        System.out.println(ret);
        //BaseMapper添加的返回值是 int
        //studentService save 返回值是boolean
    }
}
